#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n; int m;
	cin >> n >> m;
	const int N = n + 1;
	int a[N];
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= m; i++){
		next_permutation(a + 1, a + 1 + n);
	}
	for (int i = 1; i <= n; i++){
		cout << a[i] << " ";
	}
	return 0;
}